<template>
	<view>
		<!--  -->
		<!-- <view-navbar /> -->
		<!--  -->
		<view class="margin " style="margin-top: 20rpx;">
			<u-cell-group :border="false">
				<!-- 收获地址 -->
				<u-cell v-if="!checkedAddress" class="ms10 mt10" title="请选择收货地址" isLink :border="false"
					@click="show = true">
				</u-cell>
				<!-- 选择地址 -->
				<u-cell v-else @click="changeAddress" class="ms10 mt10" isLink :border="false">
					<view class="" slot="value">
						<view class="orderbetails-xinxi-right-hd">
							<view class="orderbetails-xinxi-right-name">
								{{checkedAddress.consignee }}
							</view>
							<view class="orderbetails-xinxi-right-dh">
								{{checkedAddress.phone }}
							</view>
						</view>
						<view class="orderbetails-xinxi-right-db" style="width: 600rpx;">
							{{checkedAddress.address }}
						</view>
					</view>
				</u-cell>

				<!-- 购物车 -->
				<u-cell class="ms10" :isLink="false" :border="false">
					<view slot="value">
						<block v-for="(goods, i) in cart.filter(obj => obj.goods_state == true)" :key="i">
							<!-- goods -->
							<my-goods :goods="goods" :show-radio="false" :show-num="false"
								@num-change="numberChangeHandler"></my-goods>
						</block>
					</view>
				</u-cell>

				<u-cell class="ms10" title="配送方式" isLink :border="false">
					<text slot="value" class="u-slot-value">快递</text>
				</u-cell>
				<!-- <u-cell class="ms10" title="优惠券" isLink :border="false">
					<text slot="value" class="u-slot-value color_grey">暂无优惠券</text>
				</u-cell> -->
				<!-- <u-cell class="ms10" title="买家留言" isLink :border="false">
					<text slot="value" class="u-slot-value size_14 color_grey">留言建议提前协商(250字以内)</text>
				</u-cell> -->
				<!-- 			<u-cell class="ms10" value="商家赠送" isLink icon="/static/img/buyagain/01-bao.png" :border="false">
					<view slot="title" class="u-slot-title">
						<image src="/static/img//buyagain/01-bao.png" alt="" mode="widthFix">
						<text class="u-cell-text">放心购</text>
					</view>
				</u-cell> -->
				<u-cell class="ms17" title="支付方式" isLink :border="false">
					<text slot="value" class="u-slot-value">微信支付</text>
				</u-cell>
			</u-cell-group>
		</view>
		<!--  -->
		<!-- <view class="flex margin ">
			<view class="flexflex">
				<image src="/static/img//buyagain/02-ping.png" alt="" mode="heightFix" />
				<view class="size_11">
					品质保证
				</view>
			</view>
			<view class="flexflex">
				<image src="/static/img//buyagain/03-zeng.png" alt="" mode="heightFix" />
				<view class="size_11">
					退货包运费
				</view>
			</view>
			<view class="flexflex">
				<image src="/static/img//buyagain/04-mian.png" alt="" mode="heightFix" />
				<view class="size_11">
					免费上门取退
				</view>
			</view>
			<view class="flexflex">
				<image src="/static/img//buyagain/05-zhuan.png" alt="" mode="heightFix" />
				<view class="size_11">
					专属客服
				</view>
			</view>
		</view>
 -->
		<!-- 弹框 -->
		<view @touchmove.stop.prevent="() => {}">
			<u-popup :safeAreaInsetBottom="true" :safeAreaInsetTop="true" :mode="popupData.mode" :show="show"
				:round="popupData.round" :overlay="popupData.overlay" :borderRadius="popupData.borderRadius"
				:closeable="popupData.closeable" :closeOnClickOverlay="popupData.closeOnClickOverlay" @close="close"
				@open="open">
				<view class="u-popup-slot" style="position: relative;">
					<view class="size_17 font_b"
						style="margin-top: 30rpx;margin-left: 254rpx;margin-right: 292rpx;margin-bottom: 60rpx;">
						选择收货地址
					</view>

					<!-- <u-cell size="large" title="获取微信收货地址" value="" :isLink="true"></u-cell> -->



					<u-cell @click="changeAddress" v-for="(item,index) in address" :name="item.deliveryAddressId"
						:key="index" class="ms10 mt10" isLink :border="false">
						<view class="" slot="value">
							<view class="orderbetails-xinxi-right-hd">
								<view class="orderbetails-xinxi-right-name">
									{{item.consignee }}
								</view>
								<view class="orderbetails-xinxi-right-dh">
									{{item.phone }}
								</view>
							</view>
							<view class="orderbetails-xinxi-right-db" style="width: 600rpx;">
								{{item.address }}
							</view>
						</view>
					</u-cell>
					
					
					<u-gap height="200"></u-gap>
					
					
					<button type="button"  @click="$pub.go('/pages_my/addAddress/addAddress')">新增地址</button>
					
<!-- 					<view class="  flex-cen" @click="$pub.go('/pages_my/addAddress/addAddress')"
						style="margin: 0 auto;bottom: 0;position: absolute;">
						<view class="size_16 color_white">
							新增地址
						</view>
					</view> -->
					<u-gap height="30"></u-gap>
					<!-- <u-button type="success" text="点我关闭" customStyle="width: 200rpx" @click="show = !show"></u-button> -->
				</view>
			</u-popup>
		</view>

		<!-- 结束 -->
		<view class="my-settle-container">
			<!-- 全选区域 -->
			<!-- 合计区域 -->
			<view class="amount-box ">
				<view class="flex_row ml10" style="align-items: flex-end;">
					<view class="">
						应付：<text class="amount color_orange">￥{{totalPrice}}</text>
					</view>
					<!-- 					<view class="size_12 color_grey">
						不含运费
					</view> -->
				</view>
			</view>
			<!-- 结算按钮 -->
			<view class="btn-settle" @click="settlement">支付</view>
		</view>



	</view>
</template>

<script>
	import {
		mapState,
		mapActions,
		mapMutations,
		mapGetters,
	} from 'vuex'

	export default {
		data() {
			return {
				/* 商品详情 */
				goods: {
					goods_count: 1,
					goods_id: 97,
					goods_name: "【新品】Xiaomi/小米(MI) 电视4C 55英寸 2GB+8GB 四核64位处理器 4K HDR超高清平板电视",
					goods_price: 0,
					goods_small_logo: "http://image1.suning.cn/uimg/b2c/newcatentries/0070086431-000000000822846592_1_200x200.jpg",
					goods_state: true,
				},
				showRadio: true,
				showNum: true,
				/* 地址 */
				addressStatus: false,
				/* 弹框 */
				show: false,
				popupData: {
					overlay: true,
					mode: 'bottom',
					round: 10,
					closeOnClickOverlay: true,
					closeable: true
				},
				/* 商品 */
				// cart: [],
				/* 收货地址 */
				address: [],
				/* 选择收获地址 */
				checkedAddress: null,
				/* 总价 */
				totalPrice: 0
			}
		},
		onLoad(options) {
			this.totalPrice = options.data
			// console.log(totalPrice, "totalPrice");
		},
		computed: {
			...mapState('m_user', ['cart'])
		},
		onShow() {
			this.getCate()
			this.getList()
		},
		methods: {
			...mapGetters('m_user', ['getCart']),
			/* 选择地址 */
			changeAddress(e) {
				console.log(e, "e");
				let re = this.address.map((i) => {
					if (i.deliveryAddressId == e.name) {
						this.checkedAddress = i
					}
				})
				console.log(this.checkedAddress, "this.checkedAddres");
				this.show = !this.show
			},
			/* 购物车 */
			async getCate() {
				let re = await this.$API.cartApi.getCate()
				/* 数据 */
				// this.cart = this.getCart()
			},
			/* 获取地址 */
			async getList() {
				let re = await this.$API.addressApi.getList()
				this.address = re
			},
			// 商品的数量发生了变化
			// numberChangeHandler(e) {
			// this.updateGoodsCount(e)
			// },
			/* 增加数量 */
			// async updateGoodsCount(e) {
			// 	// console.log(e.goods_count, "goods_countgoods_count");
			// 	// console.log(e.goods_id, "goods_id");
			// 	let data = {
			// 		"count": e.goods_count,
			// 		"uproductid": e.goods_id
			// 	}
			// 	// await this.$API.cartApi.changeCate(data)
			// 	await this.$API.cartApi.changeCateNum(data)
			// 	this.getCate()
			// },

			/* 跳转 */
			async settlement() {
				uni.showToast({
					title: '敬请期待',
					icon: "none"
				})
				//111111111111111111
				// //跳转支付页面详情
				// let datas = this.cart.map((i) => {
				// 	return {
				// 		count: i.goods_count,
				// 		uproductid: i.goods_id
				// 	}
				// })
				// let data = {
				// 	"deliveryAddressId": this.checkedAddress?.deliveryAddressId,
				// 	"productList": datas
				// }
				// await this.$API.orderApi.sendOrder(data)
				// uni.switchTab({
				// 	url: '/pages/my/ordercate/ordercate'
				// })
				// this.$pub.go(`/pages/my/order/order?data=${encodeURIComponent(JSON.stringify(data))}`)
				//111111111111111111
			},
			/* 	弹框 */
			open() {
				// console.log('open');
			},
			close() {
				this.show = false
				// console.log('close');
			}
		}
	};
</script>

<style lang="scss" scoped>
	page {
		background-color: #f9f9ff;
	}

	.u-cell {
		background-color: #fff;
	}

	.u-popup-slot {
		// width: 400rpx;
		height: 892rpx;
		// @include flex;
		// justify-content: center;
		// align-items: center;
	}

	.btn {
		width: 690rpx;
		height: 104rpx;
		background: #7976E9;
		border-radius: 52rpx 52rpx 52rpx 52rpx;
		opacity: 1;
	}

	/* 地址 */
	.orderbetails-xinxi-right-hd {
		display: flex;
		align-items: center;

		.orderbetails-xinxi-right-name {
			font-size: 30rpx;
			color: #161712;
		}

		.orderbetails-xinxi-right-dh {
			font-size: 22rpx;
			color: #666;
			margin-left: 30rpx;
		}

		.orderbetails-xinxi-right-db {
			font-size: 22rpx;
			// color: #666;
			color: red;
			// margin-left: 30rpx;
		}

	}


	/* 结算 */


	.my-settle-container {
		position: fixed;
		bottom: 0;
		left: 0;
		width: 100%;
		height: 100rpx;
		// 将背景色从 cyan 改为 white
		background-color: white;
		display: flex;
		justify-content: space-between;
		align-items: center;
		padding-left: 10rpx;
		font-size: 28rpx;

		.radio {
			display: flex;
			align-items: center;
		}

		.amount {
			color: #F8662D;
		}

		.btn-settle {
			height: 100rpx;
			min-width: 308rpx;
			background-color: #7976e9;
			color: white;
			line-height: 100rpx;
			text-align: center;
			padding: 0 20rpx;
		}
	}
</style>